﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SGRapidForm.Common;
using System.Collections.Specialized;
using FishWebLib;
using SGRapidForm.Permission.Entity;
using System.Data;

namespace SGRapidForm.Permission.Component
{
    public class RolePageComponent : ComponentBase
    {
        public bool RolePage_Add(string roleKeyid, string pageKeyid)
        {
            return FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RolePage_Add", null, roleKeyid, pageKeyid) > 0;
        }

        public bool RolePage_Delete(string roleKeyid, string pageKeyid)
        {
            return FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RolePage_Delete", null, roleKeyid, pageKeyid) > 0;
        }

        public bool RolePage_DeleteByRoleKeyid(string roleKeyid)
        {
            return FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RolePage_DeleteByRoleKeyid", null, roleKeyid) > 0;
        }

        public List<PermissionDetails> RolePage_GetDetailsByRoleKeyidAndModuleKeyid(string roleKeyid, string filterConditions)
        {
            NameValueCollection fieldCollection = SqlHelper.ParseQueryString(filterConditions);

            StringBuilder sql = new StringBuilder();
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "Keyid", DbType.String, " AND sgrf_permission_Module.Keyid = '{0}' "));
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "KeyWords", DbType.String, " AND (sgrf_permission_Page.PageCode LIKE '%{0}%' OR sgrf_permission_Page.PageName LIKE '%{0}%') "));

            filterConditions = sql.ToString();
            return FishBLLHelper.CallSpGetDataItemList<PermissionDetails>("sgrf_permission_RolePage_GetDetailsByRoleKeyidAndModuleKeyid", null, roleKeyid, filterConditions);
        }
    }
}
